<template>
  <div class="page">
    <van-tabs v-model="activeName" sticky @click="getDataByParams()">
      <van-tab title="全部">
        <van-panel name="a" v-for="i in allList" :key="i.orderID" :title="'￥' + i.inTotal" :desc="'下单时间:' + i.purchaseTime" @click="link(i)">
          <goods :item="i"></goods>
        </van-panel>
      </van-tab>
      <van-tab title="待发货" @click="getDataByParams(1)">
        <van-panel name="b" v-for="i in list" :key="i.orderID" :title="'￥' + i.inTotal" :desc="'下单时间:' + i.purchaseTime" @click="link(i)">
          <goods :item="i"></goods>
        </van-panel>
      </van-tab>
      <van-tab  title="已发货" @click="getDataByParams(2)">
        <van-panel name="c" v-for="i in list" :key="i.orderID" :title="'￥' + i.inTotal" :desc="'下单时间:' + i.purchaseTime" @click="link(i)">
          <goods :item="i"></goods>
        </van-panel>
      </van-tab>
      <van-tab title="退款审核中">
        <van-panel name="d" v-for="i in refundlist" :key="i.orderID" :title="'￥' + i.inTotal" :desc="'下单时间:' + i.purchaseTime" @click="link(i)">
          <goods :item="i"></goods>
        </van-panel>
      </van-tab>
      <van-tab  title="已完成" @click="getDataByParams(3)">
        <van-panel name="e" v-for="i in list" :key="i.orderID" :title="'￥' + i.inTotal" :desc="'下单时间:' + i.purchaseTime" @click="link(i)">
          <goods :item="i"></goods>
        </van-panel>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import Goods from '@/components/Goods2.vue'
import mixin from '@/mixin'
import { getMyOrders,getMyOrdersByParams } from '@/api'

export default {
  name: 'order-list',
  mixins: [mixin],
  components: {
    Goods
  },
  data() {
    return {
      activeName: '',
      list: [],
      allList: [],
      para:{},
      refundlist:{},
      item: {
        title: '跟老王学英语',
        num: 2,
        price: 0.01,
        oPrice: 200.00,
        desc: '王小二学英语是给小孩子的英语启蒙王小二学英语是给小孩子的英语启蒙王小二学英语是给小孩子的英语启蒙王小二学英语是给小孩子的英语启蒙',
        tag: '限时团购',
        img: 'https://edu-image.nosdn.127.net/07e3b8f9-5721-47bb-a710-ab8cce9cab9e.jpg'
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      getMyOrders().then(res => {
        this.allList = res
        console.log(777)
        console.log(res)
        console.log(777)
      })
    },
    getDataByParams(){
      if(this.activeName != 0 && this.activeName != 3){
        console.log(this.activeName)
          switch (this.activeName) {
            case 1:
              this.para = {
                "postStatus":2
              }
              break
            case 2:
              this.para = {
                "postStatus":1
              }
              break
            case 4:
              this.para = {
                "refundStatus":2
              }
              break
          }
        getMyOrdersByParams(this.para).then(res => {
          this.list = res
          console.log(555)
          console.log(res)
          console.log(555)
        })
      }
    },
    link(i) {
      // this.$router.push(`/order-detail/${i.id}`)\
      // console.log(i);
      // return
      this.$router.push({
        path: `/order-detail/${i.orderID}`,
        query: {
          item:i
        }
      })

    }
  }
}
</script>
<style scoped lang="stylus" rel="stylesheet/stylus">
@import '../style/mixin'
.van-panel
  margin-bottom $part-width
.van-cell__title
  flex auto
</style>
